package com.sfx.handler.exception;

import com.sfx.domain.ResponseResult;
import com.sfx.enums.AppHttpCodeEnum;
import com.sfx.exception.SystemException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-07-12
 * Time: 15:35
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler{
    @ExceptionHandler(SystemException.class)
    public ResponseResult systemExceptionHandler(SystemException e) {
        log.error("出现了SystemException异常！ {}",e);
        return ResponseResult.errorResult(e.getCode(),e.getMessage());
    }

    /**
     * 捕获除了自定义异常以外的其他异常
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    public ResponseResult ExceptionHandler(Exception e) {
        log.error("出现了Exception！ {}",e);
        return ResponseResult.errorResult(AppHttpCodeEnum.SYSTEM_ERROR,e.getMessage());
    }
}